#!/usr/bin/env node

const fs = require('fs');

if(process.argv.length !== 3){
  console.error('命令行格式：cmd file_name');
  process.exit(1);
}

const width = 16,
      height = 16;

//因为有32位，占4字节，所以乘4
let pixeByteSize = width * height * 4;
//54是头文件占的字节
let totalSize = pixeByteSize + 54;



let buf = Buffer.alloc(totalSize);
buf.fill(0);

//head
buf.write('BM');
buf.writeUInt32LE(totalSize,0x02);
buf.writeUInt32LE(54,0x0a);
buf.writeUInt32LE(40,0x0e);
buf.writeUInt16LE(32,0x1c);
buf.writeUInt16LE(pixeByteSize,0x22)
buf.writeInt32LE(height,0x16);
buf.writeInt32LE(width,0x12);

//data
for(let i=54; i<totalSize; i+=4){
  buf.writeUInt32LE(0xff0000ff,i);
}


fs.writeFile('./out.bmp',buf,(err)=>{
  if(err != null){
    console.error(err);
    process.exit(1);
  }
})



